package com.tbit.uqbike.client.util;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;

/**
 * @Author: chen
 * @Description:
 * @Date: 创建于 15:06 2022/6/23
 */
public class TestRateLimiter {


    public static void main(String[] args) {
        final RateLimiter rateLimiter = RateLimiter.create(10);
        for (int i = 0; i < 10; i++) {
            long timeOut = (long) 0.5;
            boolean isValid = rateLimiter.tryAcquire(timeOut, TimeUnit.SECONDS);
            System.out.println("任务" + i + "执行是否有效:" + isValid);
            if (!isValid) {
                continue;
            }
            System.out.println("任务" + i + "在执行");
        }
        System.out.println("结束");
    }

    public Boolean create() {

        return null;
    }


}
